package com.sh.xxj.rebot.service;

import java.awt.Font;
import java.io.File;

public class FontService {

	private static FontService instance;

	// public static String ttfPath =
	// "D:\\workspace_myeclipse10\\xxj_robot\\res\\font\\msyhbd.ttf";

	private Font font;

	private FontService() {

	}

	// 得到实例
	public static FontService getInstance() {
		if (instance == null) {
			instance = new FontService();

		}
		return instance;

	}

	public static void main(String[] args) {
		FontService fs = FontService.getInstance();
		fs.getFont();
	}

	public Font getFont() {
		if (font == null) {

			try {
				// InputStream is = new BufferedInputStream(new
				// FileInputStream(ttfPath) );
				// font = Font.createFont(Font.TRUETYPE_FONT, is);
				font = Font.createFont(Font.TRUETYPE_FONT, new File(
						ConfigService.FONT_PATH));
				font = font.deriveFont(Font.BOLD, 20f);

				// font=new Font("宋体", Font.PLAIN, 16);
			} catch (Exception ex) {
				ex.printStackTrace();
				System.err.println(ConfigService.FONT_PATH
						+ " not loaded.  Using serif font.");
				font = new Font("serif", Font.PLAIN, 24);
			}
		}
		return font;
	}
}
